package com.macasa.panel.entity.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.IApacheService;
import com.macasa.panel.entity.api.IApacheServiceVhost;

@Entity
@Table(name = "apache_service_vhost")
@SequenceGenerator(name = "ApacheServiceVhost_SEQ", sequenceName = "ApacheServiceVhostIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class ApacheServiceVhost extends AbstractModel<Integer> implements IApacheServiceVhost {
	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= -6976431170225030822L;

	@Id
	@Column(name = "apache_service_vhost_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "ApacheServiceVhost_SEQ")
	private Integer				id;

	@Column(name = "server_name", nullable = false)
	private String				serverName;

	@Column(name = "document_root", nullable = true)
	private String				documentRoot;

	@Column(name = "redirect_to", nullable = true)
	private String				redirectTo;

	@Column(name = "server_admin", nullable = true)
	private String				serverAdmin;

	@Column(name = "lock_base_dir", nullable = true)
	private Boolean				lockBaseDir;

	@Column(name = "safe_mode", nullable = true)
	private Boolean				safeMode;

	@Column(name = "magic_quotes_gpc", nullable = true)
	private Boolean				magicQuotesGpc;

	@Column(name = "register_globals", nullable = true)
	private Boolean				registerGlobals;

	@Column(name = "add_default_charset", nullable = true)
	private String				addDefaultCharset;

	@Column(name = "allow_from", nullable = true)
	private String				allowFrom;

	@Column(name = "bandWidth", nullable = true)
	private String				bandWidth;

	@Column(name = "min_band_width", nullable = true)
	private String				minBandWidth;

	@Column(name = "max_connection", nullable = true)
	private String				maxConnection;

	@Column(name = "port", nullable = false)
	private Integer				port;

	@Column(name = "https", nullable = false)
	private Boolean				https;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, targetEntity = com.macasa.panel.entity.impl.ApacheService.class)
	@JoinColumn(name = "fk_apache_service_id", nullable = false)
	private IApacheService		apacheService;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof ApacheServiceVhost)) {
			return false;
		}

		final ApacheServiceVhost other = CastHelpers.cast(obj, ApacheServiceVhost.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.serverName, other.serverName) && Objects.equal(this.documentRoot, other.documentRoot)
				&& Objects.equal(this.redirectTo, other.redirectTo) && Objects.equal(this.serverAdmin, other.serverAdmin)
				&& Objects.equal(this.lockBaseDir, other.lockBaseDir) && Objects.equal(this.safeMode, other.safeMode)
				&& Objects.equal(this.magicQuotesGpc, other.magicQuotesGpc) && Objects.equal(this.registerGlobals, other.registerGlobals)
				&& Objects.equal(this.addDefaultCharset, other.addDefaultCharset) && Objects.equal(this.allowFrom, other.allowFrom)
				&& Objects.equal(this.bandWidth, other.bandWidth) && Objects.equal(this.minBandWidth, other.minBandWidth)
				&& Objects.equal(this.maxConnection, other.maxConnection) && Objects.equal(this.port, other.port) && Objects.equal(this.https, other.https);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.serverName, this.documentRoot, this.redirectTo, this.serverAdmin, this.lockBaseDir, this.safeMode,
				this.magicQuotesGpc, this.registerGlobals, this.addDefaultCharset, this.allowFrom, this.bandWidth, this.minBandWidth, this.maxConnection,
				this.port, this.https);
	}
}
